$(function(){

    var mydate = new Date();
    var str = '"' + mydate.getFullYear() + "-";
    str += (mydate.getMonth()+1) + "-";
    str += mydate.getDate() + '"';
    console.info("当前时间："+str )
    var addDate = new Date(new Date(str).getTime() + (1000 * 60 * 60 * 24));
    var str1 = '"' + addDate.getFullYear() + "-";
    str1+= (addDate.getMonth()+1) + "-";
    str1 += addDate.getDate() + '"';
    console.info("第二天时间："+str1)

    $('#datetimepicker1').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn'),
        defaultDate: str
    });
    $('#datetimepicker2').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn'),
        defaultDate: str1
    });
    //城市选择
    var test=new Vcity.CitySelector({input:'citySelect'});

    var picker1 = $('#datetimepicker1').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    });
    var picker2 = $('#datetimepicker2').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    });
    //动态设置最小值
    picker1.on('dp.change', function(e) {
        picker2.data('DateTimePicker').minDate(e.date);
    });
    //动态设置最大值
    picker2.on('dp.change', function(e) {
        picker1.data('DateTimePicker').maxDate(e.date);
    });

    $("#login").bootstrapValidator({
        live: 'enabled', //验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证
        excluded: [':disabled', ':hidden', ':not(:visible)'], //排除无需验证的控件，比如被禁用的或者被隐藏的
        submitButtons: '#loginActive', //指定提交按钮，如果验证失败则变成disabled，但我没试成功，反而加了这句话非submit按钮也会提交到action指定页面
        message: '通用的验证失败消息', //好像从来没出现过
        feedbackIcons: { //根据验证结果显示的各种图标
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            password: {
                validators: {
                    notEmpty: { //检测非空
                        message: '请输入密码'
                    },
                }
            },
            realname: {
                validators: {
                    notEmpty: { //检测非空,radio也可用
                        message: '请输入电话'
                    },
                    /*  stringLength: { //检测长度
                          min: 3,
                          max: 5,
                          message: '长度必须在3-10之间'
                      },*/
                    regexp: { //正则验证
                        /*regexp: /^[a-zA-Z0-9_\.]+$/,*/
                        regexp:/^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9]))\d{8}$/,
                        message: '不符合要求'
                    },
                }
            }
        }
    });
    $('#go').click(function () {
        var citySelect=$('#citySelect').val();
        var timeInput=$('#timeInput').val();   //入住时间
        var timeInput1=$('#timeInput1').val();  //离店时间
        window.location.href=ctx+"hotellist/listpage?citySelect="+citySelect
    })

    $('#loginActive').click(function () {
        $("#login").bootstrapValidator('validate'); //提交验证
        if($("#login").data('bootstrapValidator').isValid()) { //获取验证结果，如果成功，执行下面代码
            var resultJson={};
            resultJson.realname=$('#realname').val();
            resultJson.password=$('#password').val();
            $.ajax({
                url:"logined",
                type:"post",
                data:resultJson,
                dataType:"json",
                success : function (data) {
                    if (data.msg == '登录成功'){
                        if (data.userState != 1){
                            $('#loginModal').modal('hide')
                            toastr.success(data.msg);
                            setTimeout(function () {
                                window.location.href=ctx + "home"
                            },1000)
                        }else {
                            $('#loginModal').modal('hide')
                            toastr.error("账号已被拉黑 原因:"+data.userReason)
                        }

                    }
                    else {
                        toastr.error(data.msg+",重新登录")
                    }
                },
                error: function (data) {
                    toastr.error(data.msg+",重新登录")
                }
            })
        }
    })
});
var t = 0;
function setBackground(){
    switch (t%3){
        case 0 : {
            $('#hotelPic').css("background","url('/static/img/home/hotelHome4.jpg') no-repeat center center fixed ");
            break;
        }
        case 1 : {
            $('#hotelPic').css("background","url('/static/img/home/hotelHome5.jpg') no-repeat center center fixed ");
            break;
        }
        case 2 :{
            $('#hotelPic').css("background","url('/static/img/home/hotelHome6.jpg') no-repeat center center fixed ");
            break;
        }
    }
    t++;
}
setInterval("setBackground()",5000);
